package com.ruoyi.web.controller.equ;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.Pictures;
import com.deepoove.poi.policy.PictureRenderPolicy;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equ.domain.EquAsset;
import com.ruoyi.equ.service.IEquAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;

/**
 * 资产设备Controller
 *
 * @author ruoyi
 * @date 2025-11-05
 */
@RestController
@RequestMapping("/equ/asset")
public class EquAssetController extends BaseController
{
    @Autowired
    private IEquAssetService equAssetService;

    /**
     * 查询资产设备列表
     */
    @PreAuthorize("@ss.hasPermi('equ:asset:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ModelAttribute EquAsset equAsset)
    {
        startPage();
        List<EquAsset> list = equAssetService.selectEquAssetList(equAsset);
        return getDataTable(list);
    }

    /**
     * 查询可以报废的资产设备列表-'正常','待报废'
     */
    @PreAuthorize("@ss.hasPermi('equ:asset:list')")
    @GetMapping("/listCommon")
    public TableDataInfo listCommon(@ModelAttribute EquAsset equAsset)
    {
        startPage();
        List<EquAsset> list = equAssetService.selectEquAssetListCommon(equAsset);
        return getDataTable(list);
    }

    /**
     * 导出资产设备列表
     */
    @PreAuthorize("@ss.hasPermi('equ:asset:export')")
    @Log(title = "资产设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ModelAttribute EquAsset equAsset)
    {
        List<EquAsset> list = equAssetService.selectEquAssetList(equAsset);
        ExcelUtil<EquAsset> util = new ExcelUtil<EquAsset>(EquAsset.class);
        util.exportExcel(response, list, "资产设备数据");
    }

    /**
     * 获取资产设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('equ:asset:query')")
    @GetMapping(value = "/{assetId}")
    public AjaxResult getInfo(@PathVariable("assetId") Long assetId)
    {
        return success(equAssetService.selectEquAssetByAssetId(assetId));
    }

    /**
     * 新增资产设备
     */
    @PreAuthorize("@ss.hasPermi('equ:asset:add')")
    @Log(title = "资产设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquAsset equAsset)
    {
        return toAjax(equAssetService.insertEquAsset(equAsset));
    }

    /**
     * 修改资产设备
     */
    @PreAuthorize("@ss.hasPermi('equ:asset:edit')")
    @Log(title = "资产设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquAsset equAsset)
    {
        return toAjax(equAssetService.updateEquAsset(equAsset));
    }

    /**
     * 删除资产设备
     */
    @PreAuthorize("@ss.hasPermi('equ:asset:remove')")
    @Log(title = "资产设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{assetIds}")
    public AjaxResult remove(@PathVariable("assetIds") Long[] assetIds)
    {
        return toAjax(equAssetService.deleteEquAssetByAssetIds(assetIds));
    }
    /**
     * 查询所有资产设备名称
     * @return
     * */
    @PreAuthorize("@ss.hasPermi('equ:asset:list')")
    @GetMapping("/getAllAssetName")
    public AjaxResult getAllAssetName(){
        return success(equAssetService.getAllAssetName());
    }
}
